package com.demo.controller;


import com.demo.entity.PrintTemplate;
import com.demo.response.Result;
import com.demo.service.IPrintTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * 文书模板 前端控制器
 * @author zm
 * @since 2020-11-24
 */
@RestController
@RequestMapping("/printTemplate")
@Api(tags = "文书模板类")
public class PrintTemplateController {
    @Autowired
    IPrintTemplateService templateService;

    @ApiOperation("编辑文书模板")
    @PostMapping("/updatePrintTemplate")
    public Result updatePrintTemplate(@RequestBody PrintTemplate printTemplate, BindingResult result){
        if (result.hasErrors()){
            return Result.error(result.getFieldError().getDefaultMessage());
        }
        return templateService.updatePrintTemplate(printTemplate);
    }

    @ApiOperation("查询文书模板")
    @GetMapping("/printTemplateList")
    public Result printTemplateList(@RequestParam(name = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
                                    @RequestParam(name = "pageSize",required = false,defaultValue = "10")Integer pageSize,
                                    @RequestParam(name = "templateId",required = false)Integer templateId,
                                    @RequestParam(name = "templateType",required = false)Integer templateType,
                                    @RequestParam(name = "templateName",required = false)String templateName){
        return templateService.printTemplateList(pageNumber, pageSize, templateId, templateType, templateName);

    }


}
